In This Part
by K. David White
In This Chapter
If you are looking for information regarding wedding registries, youve come to the wrong place! This chapter discusses a commonly overlooked mechanism available in Windows that is very important to the commercial success of your application: the Windows Registry.
If you are somewhat familiar with the Registry, you might be asking what a chapter about the Windows Registry is doing in a book about MFC programming? Dont you want to get under the covers of MFC here?
Good question! Typically, you see this topic covered in topic-specific books. What Ive noticed is that this topic is usually covered from a system administration viewpoint, with only passing mention of the API. I have seen some very good articles on the Registry in different magazines, but they only scratch the surface. Most authors and publishers simply feel that the Registry is a peripheral topic not directly related to programming. Most bookstores place a Registry book on the Operating System shelf!
Many moons ago, when I started developing Windows applications, I was a veteran newbie to the Windows world, not paying attention to the use of INI files and (later) the Registry. The primary reason for this was that I was reading and relying on programming books (such as this one) to provide me with the information that I needed. Coming from a different operating system (VMS) background (thus the veteran status), I didnt get to know the operating system components very well before jumping in and developing an application. It wasnt long before I came face to face with the installation monster that forced me to learn the Registry. When I realized how easy it was, I decided to investigate further.
In the not too distant past, Windows applications relied on ASCII-based files to store important information. These files came in the form of *.INI files and were usually stored in either the applications install directory or in the Windows system directory.
Note:Before the method of using INI files, Microsoft used the infamous CONFIG.SYS and AUTOEXEC.BAT (which are still in use). Applications had to maintain their own configuration files. Then along came the system-level INI files. These were PROGMAN.INI, SYSTEM.INI, WIN.INI, and CONTROL.INI.
This was fine as long as the application wasnt upgraded or moved. These files were easy to change, which gave system administrators a quick-fix method for correcting operating system and application problems. However, this flexibility would many times come back to haunt the administrator. Easy to fix, easy to break.
Microsoft, with the release of Windows 3.1, created the Registry. Remarkably, this creation, although simple, has created much confusion and frustration among software developers. In this chapter, you will develop a better understanding of what the Registry is for and how to use it effectively.
What this chapter is not, however, is an in-depth guide to optimizing the Registry to make Windows NT or Windows 95/98 more efficient. This chapter looks at the Registry from the applications point of view.
Imagine an application that requires no external direction as to where to run, where to display its interface, what to display on its interface, and so on. You are wondering how an application might know about these things without some sort of initialization/remembrance mechanism. One method to store important initialization and state data would be to put it into flat files that the application would read in at startup. These files, commonly called INI files, were widely used, but they are not without their problems:
Although this list is not complete, you can readily see that the system of maintaining configuration in flat files can quickly run amuck.
Enter the Registry. Originally, the Registry was developed to assist the system administrator in controlling, configuring, and optimizing the Windows operating system. Although that is its primary purpose today, many applications also use it for a plethora of configuration and state information. Many developers believe that the Registry shouldnt really be used for GUI-related items, but what better way to save important interface information when the application is shut down?
Note:Of course, there are limitations to what can be stored in the Registry. The Registry is a file system, and the larger those files get, the longer the Windows operating system takes to boot. There is also a size boundary to the Registry that is operating system-dependent. With this in mind, you might want to limit the information stored. Stick with important configuration and state information, and store buffered data to a file.
I will define some terms here relating to the usage of the Registry.
Configuration data is that data that defines not only the operating system runtime parameters, but also the runtime information for applications. The Registry is perfect for defining items such as background color, screen size and location, number of users, and COM property data. Sticking this information away in the Registry whenever an application exits makes it easy to restore at the next startup.
You might be thinking that information about a service would fall under configuration or even state, but services are different from user applications. What sets the service apart from other applications is that the interface is normally handled through the Control Panel. Services generally dont have a user interface; therefore, certain information can only be maintained using flat files or the Registry.
State is commonly referred to in programming circles as the point in the programmatic flow that maintains a constant definition. In simpler terms, programmatic flow has steps involved in completion of the algorithm. A state is simply the condition of the data at a defined step. Many control applications are nothing more than state machines, where the applications state defines the step in the control flow. The Registry lends itself to managing state data for not only the operating system, but also any application.